// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "TestAnaly.h"

#include "MainFrm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMainFrame

IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
	//{{AFX_MSG_MAP(CMainFrame)
	ON_WM_CREATE()
	ON_WM_SIZE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

static UINT indicators[] =
{
	ID_SEPARATOR,           // status line indicator
	ID_INDICATOR_CAPS,
	ID_INDICATOR_NUM,
	ID_INDICATOR_SCRL,
};

/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
{
	// TODO: add member initialization code here
	m_bInit = FALSE;
	
	m_pToolView     = NULL;
	m_pStandardView = NULL;
	m_pCheckView    = NULL;
}

CMainFrame::~CMainFrame()
{
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;

	ShowWindow(SW_SHOWMAXIMIZED);

	if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
		!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}

	if (!m_wndStatusBar.Create(this) ||
		!m_wndStatusBar.SetIndicators(indicators,
		  sizeof(indicators)/sizeof(UINT)))
	{
		TRACE0("Failed to create status bar\n");
		return -1;      // fail to create
	}

	// TODO: Delete these three lines if you don't want the toolbar to
	//  be dockable
	//m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
	//EnableDocking(CBRS_ALIGN_ANY);
	//DockControlBar(&m_wndToolBar);

	return 0;
}



BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/,
								CCreateContext* pContext)
{
	CRect rect;
	GetClientRect(&rect);

	// create splitter window
	if (!m_wndSplitter.CreateStatic(this, 1, 2))
		return FALSE;


	if ( !m_wndSplitter2.CreateStatic(&m_wndSplitter,1, 2, 1,	// 2 rows, 1 col
		WS_CHILD | WS_VISIBLE,
		m_wndSplitter.IdFromRowCol( 0, 0 ) ) )
		return FALSE;

	if( !m_wndSplitter2.Set4Bitmaps(IDB_BMPLEFT,IDB_BMPRIGHT,IDB_BMPDOWN,IDB_BMPUP) )
	{
		//AfxMessageBox("load error");
		return FALSE;
	}

	int nWidth = rect.Width()-TOOLVIEWWIDTH;
	nWidth /= 2;


	if( !m_wndSplitter2.CreateView(0, 0, RUNTIME_CLASS(CStandardView), CSize(nWidth, 100), pContext ) )
	{
		m_wndSplitter.DestroyWindow();
		return FALSE;
	}

	if( !m_wndSplitter2.CreateView(0, 1, RUNTIME_CLASS(CCheckView), CSize(nWidth, 100), pContext ) )
	{
		m_wndSplitter.DestroyWindow();
		return FALSE;
	}

	if( !m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CToolView), CSize(TOOLVIEWWIDTH, 100), pContext ) )
	{
		m_wndSplitter.DestroyWindow();
		return FALSE;
	}
		
	m_pStandardView = (CStandardView *)m_wndSplitter2.GetPane(0,0);
	m_pCheckView    = (CCheckView    *)m_wndSplitter2.GetPane(0,1);
	m_pToolView     = (CToolView     *)m_wndSplitter.GetPane(0,1);

	m_pToolView->m_pMainFrame     = this;
	m_pStandardView->m_pMainFrame = this;
	m_pCheckView->m_pMainFrame    = this;


	m_pToolView->Initialize();

	m_pStandardView->m_bInit = true;

	m_bInit = TRUE;
	
	return TRUE;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CFrameWnd::PreCreateWindow(cs) )
		return FALSE;
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
	CFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers


void CMainFrame::OnSize(UINT nType, int cx, int cy) 
{
	CFrameWnd::OnSize(nType, cx, cy);

	if( !m_bInit )
	{
		return;
	}
	
	// TODO: Add your message handler code here

	if( cx > TOOLVIEWWIDTH )
	{
		int nWidth = cx-TOOLVIEWWIDTH;
	
		m_wndSplitter.SetColumnInfo(0,nWidth,0);
		m_wndSplitter.SetColumnInfo(1,TOOLVIEWWIDTH,0);

		nWidth /= 2;

		m_wndSplitter2.SetColumnInfo(0,nWidth,0);
		m_wndSplitter2.SetColumnInfo(1,nWidth,0);
	}
}
